package ar.uba.tleng.g99.expregs.automata;

import java.util.HashMap;
import java.util.Map;

public class NodeD {

	final Map<Character, NodeD> childs;

	public NodeD() {
		this.childs = new HashMap<Character, NodeD>();
	}

	public void addTransition(Character c, NodeD n) {
		if (childs.containsKey(c) && childs.get(c) != n) {
			throw new RuntimeException(
					"Trato de agregarse un segundo nodo a una transicion.");
		}
		childs.put(c, n);
	}
	
	/**
	 * Returns the {@link NodeD} pointed by the c character.
	 * 
	 * @param c the transition character.
	 * @return the destination {@link NodeD}, or null if none. 
	 */
	public NodeD move(Character c) {
		if (!childs.containsKey(c)) {
			return null;
		}
		return childs.get(c);
	}

}
